package com.hy.api.weixin;

import com.hy.entitys.Chapter;
import com.hy.service.WeChatService;
import com.hy.utils.WxUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@Api(value ="/wx",tags="小说模块")
@RestController
@RequestMapping("/wx")
public class ApiWeixinController {

    @Autowired
    private  WeChatService weChatService;

    public static WxUtils wxUtils= new WxUtils();
    @RequestMapping(value = "/do",method =RequestMethod.GET)
    @ApiOperation(value = "/do",tags ="绑定")
    public String getChapter(String signature,String timestamp,String nonce, String echostr){
        return wxUtils.check(signature, timestamp, nonce, echostr);
    }

    @RequestMapping(value = "/do",method =RequestMethod.POST)
    @ApiOperation(value = "/do",tags ="绑定")
    public void getChapter(HttpServletRequest request, HttpServletResponse response){


        response.setCharacterEncoding("UTF-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String parseXml =weChatService.processRequest(request);
        out.print(parseXml);


    }
}
